\documentclass[border=10pt,tikz]{standalone}
\usepackage{pgfplots,pgfplotstable,tikz}
\usetikzlibrary{intersections}
\usepackage{verbatim}
\usepackage{moresize}
\usetikzlibrary{calc}
\usepackage{datatool}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{xspace} 
\usepackage{etoolbox}
\usepackage{multirow}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing}
\pgfplotsset{compat=1.13}
\usepackage{fp}


\definecolor{green}{RGB}{68,126,35}
\definecolor{blue}{RGB}{19,30,92}
\definecolor{red}{RGB}{219,51,24}

% Defines "sgn" function
\def\sgn{\mathop{\rm sgn}\nolimits} 
% Defines the expectation function
\def\E{\mathop{\mathrm{E}}\nolimits} 

% Defines a function that ignores the zero on the y- or the x-axis, such that the origin
% is only labeled once. Activate in the axis options by adding the key: "ignore zero=x" or ""ignore zero=y."
\pgfplotsset{ignore zero/.style={%
		#1ticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi}
	}}

\pgfkeys{/pgf/number format/.cd, fixed, precision=2} %set precision of the printed numbers

\begin{document}
% TAKE INPUTS FROM THE FOLLOWING FILE: "linmte_no_covars_Y_num_oregonnumhh1.csv" --- generated in Stata by the program file: "linmte_no_covars_graph_data.do"
\begingroup\catcode`"=9 % ignore quotation marks in csv file
\csvreader[head to column names, filter test = \ifnumequal{\thecsvinputline}{2}]{linmte_no_covars_Y_num_oregonnumhh1.csv}{}{
	% Enforce display of decimal points
	\pgfkeys{/pgf/number format/fixed zerofill=true}
	
	% Store Labels
	\newcommand*{\D}{\Dlab\xspace}
	\newcommand*{\Y}{\Ylab\xspace}
	
	% [yaxismin, yaxismax, yaxislength] Calculate graphing region for the y-axis
	\pgfmathsetmacro\yaxismin{0}
	\pgfmathsetmacro\yaxismax{\BTTO*1.13}
	\pgfmathsetmacro\yaxislength{\yaxismax-\yaxismin}
	
	\pgfmathsetmacro\LATE{\LATO - \LAUO}
	\pgfmathsetmacro\UOT{\LAUO - \IUUO}

% MTE(pC) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
[>=stealth,element/.style={align=left},square/.style={regular polygon,regular polygon sides=4}]
\tikzset{
	every pin/.style={black},
	%every pin edge/.style={draw=black}
}
% Axis options
\begin{axis}[					
	width=15cm,					% width of chart
	height=10cm,				% height of chart
	xlabel={$U_D$: unobserved net cost of treatment},				% x-axis title
	ylabel={\Y},					% y-axis title
	ylabel style={rotate=0},  % rotate the y-axis title
	samples=100,  				% sets the resolution for curved lines
	xmin=0,xmax=1,			    % x-axis range
	ymin=0,
	%ymin=1.2*\Dinterceptr,ymax=1.05*\yaxismax,			% y-axis range
	ignore zero=y,			    % ignore the zero on the y-axis (defined in preamble)
	xtick={0,\pB,\pI,1},	    % only show these x ticks
	xticklabels={0,$p_C=\pgfmathprintnumber{\pB}$, $p_I=\pgfmathprintnumber{\pI}$,1}, % label x ticks
	ytick={0,\IUUO, \LAUO, \LATO, \BTTO},	    % only show these y ticks
	ymax = \yaxismax,
	legend style={
		draw=none,
		at={(1,1)},
		anchor=north east,
		fill=none
	},	% set legend style, specifically no outline
	legend cell align={left},	% align legend content to the left
	clip=false,					% place nodes outside of plot area
			xticklabel style={
									yshift=-5.5ex,
									name=label,
									append after command={(label.north) edge [solid] ++(0,6ex)},
									/pgf/number format/fixed,
									/pgf/number format/precision=2},
								x label style={at={(axis description cs:0.5,-0.15)},anchor=north}, % ncrease distance between title and x-axis
								yticklabel style={/pgf/number format/fixed},
								% place some extra y ticks ...
								extra y ticks={0},
								% ... but do not repeat the already existent labels
								% (from the "normal" ticks) ...
								extra y tick labels={0},
								% ... and set the style of the extra ticks to `major'
								extra tick style={
									grid=major,
								},
	]		
	

	% lato
	\addplot[
		line width=2.2pt, line cap=round, green, dashed, dash pattern=on 0.6pt off 3.5pt
	] coordinates {(\pB,\LATO) (\pI,\LATO)};	% plots a straight line between these coordinates
	%Midpoint of LATO 
	\node[outer sep=0pt,circle, fill=green,inner sep=2pt] (P) at (0.5*\pB+0.5*\pI, \LATO) {};


	% lauo
	\addplot[
		line width=1.8pt, blue, dashed, dash pattern=on 3.8pt off 2pt
	] coordinates {(\pB,\LAUO) (\pI,\LAUO)};
	% Midpoint of lauo
	\node[outer sep=1.3pt,square, fill=blue,inner sep=2pt] (P) at (0.5*\pB+0.5*\pI, \LAUO) {};
	
	
	% iuuo
	\addplot[
		line width=1.8pt, blue, dashed, dash pattern=on 3.8pt off 2pt
	] coordinates {(\pI,\IUUO) (1,\IUUO)};
	% Midpoint of iuuo
	\node[outer sep=1.3pt,square, fill=blue,inner sep=2pt] (P) at (0.5*\pI+0.5, \IUUO) {};
	
	% btto
	\addplot[
		line width=2.2pt, line cap=round, green, dashed, dash pattern=on 0.6pt off 3.5pt
	] coordinates {(0,\BTTO) (\pB,\BTTO)};
	% Midpoint of AT treated outcome
	\node[outer sep=0pt,circle, fill=green,inner sep=2pt] (P) at (0.5*\pB, \BTTO) {};
		
	%Arrow for Untreated Outcome test
	\addplot[thick, <- , color = blue, mark = none] coordinates{(\pI, \LAUO-0.01) (\pI, \IUUO)}; 
	\node at (axis cs:0.55,1.14) [anchor=east, color=blue] {untreated}; 
	\node at (axis cs:0.54,1.06) [anchor=east, color=blue] {outcome}; 
	\node at (axis cs:0.57,0.98) [anchor=east, color=blue] {test statistic}; 
	\node at (axis cs:0.53,0.90) [anchor=east, color=blue] {$=\pgfmathprintnumber{\UOT}$}; 
	
	%Arrow for LATE
	\draw[->,thick,red](axis cs:0.5*\pB+0.5*\pI,\LAUO+0.01)--(axis cs:0.5*\pB+0.5*\pI,\LATO-0.01);
	\node[red, right] at (axis cs:0.30,1.35) {$\text{LATE}$};
	\node[red, right] at (axis cs:0.295,1.26) {$=\pgfmathprintnumber{\LATE}$};
	
	
	% add legend
	\legend{treated,,untreated,,,,}
	
			% Put Always Takers, Compliers, and Never Takers on the x-axis
		\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (0,\yaxismin) -- (\pB, \yaxismin) node[pos=0.5, below, yshift = 0pt, align=left] {Always \\ Takers};
		\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (\pB,\yaxismin) -- (\pI, \yaxismin) node[pos=0.5, below, yshift = 0pt] {Compliers};
		\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (\pI,\yaxismin) -- (1, \yaxismin) node[pos=0.5, below, yshift = 0pt] {Never Takers};


\end{axis}
\end{tikzpicture}

	
}
\end{document}